#pragma once
#include <game/Config.h>

#include <string>
#include <Atom.h>
#include <Signals.h>

namespace liba {
class Atom;
class Object2D;
namespace xml {
class ObjectANSI;
} // namespace xml
} // namespace liba

ARELLO_GAME_NAMESPACE_DECL_START
class Properties;
namespace input {
struct TouchEvent;
} // namespace input
namespace controls {

enum InputSharingMode
{
	/** Continue processing input for controls that have greater Z value */
	INPUT_SHARE_CONTINUE,
	/** Don't send input to controls with greater Z value but continue interactions with ones having equal or less */
	INPUT_SHARE_STOP_DIGGING,
	/** Don't share input to other controls. Abort touch events with controls that already received OnTouchStarted notifications. */
	INPUT_SHARE_EXCLUSIVE
};

class Control
{
	friend class ControlLoader;

public:
	Control(const liba::Atom& name, liba::Object2D* object2d);
	virtual ~Control();

	const Properties& GetProperties() const;
	const liba::Atom& GetName() const;
	liba::Object2D* GetObject2D() const;
	
	void SetEnabled(bool value);
	bool IsEnabled();

	void SetModalLevel(int value);
	int GetModalLevel();

	bool IsOrphaned();
	liba::signals::signal<void ()>& Orphaned();

	virtual liba::xml::ObjectANSI* GetLoader() { return 0; }
public:
	virtual InputSharingMode GetSharingMode() = 0;
	virtual void OnTouchStarted(const input::TouchEvent& ev) = 0;
	virtual void OnTouchMove(const input::TouchEvent& ev) = 0;
	virtual void OnTouchFinished(const input::TouchEvent& ev) = 0;
protected:
	void SetProperties(const Properties &prop);
private:
	boost::scoped_ptr<struct ControlPrivates> privates;
};

} // namespace controls
ARELLO_GAME_NAMESPACE_DECL_END